﻿Imports System.Data.OleDb
Imports System.Data

Public Class Gallery
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'WILL USE THIS CODE LATER -- DONT DELETE
        'If Not IsPostBack Then
        '    Dim objDI As New System.IO.DirectoryInfo(Server.MapPath("~/Images/UserUploads/"))
        '    Me.dlQLImages.DataSource = objDI.GetFiles("*.jpg")
        '    Me.dlQLImages.DataBind()
        'End If
    End Sub

    Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSubmit.Click
        Dim myGUID = Guid.NewGuid()
        Dim newFileName As String = myGUID.ToString() & ".jpg"
        Dim fileLocationOnServerHardDisk = Request.MapPath("Images/UserUploads/") & "/" & newFileName
        'imgUpload.SaveAs(fileLocationOnServerHardDisk)
        imgUpload.SaveAs(fileLocationOnServerHardDisk)
        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("carsconn").ConnectionString)
        Dim SqlString As String = "insert into Vehicle_UserUploads (Veh_Name,Veh_Description,Veh_UserUpload) values (@f1,@f2,@f3)"
        oleDbConn.Open()
        Dim cmd As OleDbCommand = New OleDbCommand(SqlString, oleDbConn)
        cmd.CommandType = CommandType.Text
        cmd.Parameters.AddWithValue("@f1", txtN.Text)
        cmd.Parameters.AddWithValue("@f2", txtD.Text)
        cmd.Parameters.AddWithValue("@f3", "Images/UserUploads/" & newFileName)

        cmd.ExecuteNonQuery()
        oleDbConn.Close()
        Response.Redirect("Gallery.aspx")
    End Sub
End Class